<?php

class model_wishFavorites extends L {

    /**
     * 描述 ：分页的查询语句拼接
     * 作者 ：Zoro.Zhu
    **/
    public static function searchSql($params = array()){
        $sql = "SELECT
             `productId`, `data`, `addName`, `addDate`
        FROM
            `wish_favorites`
        WHERE 1";

        $sql .= " AND addName = '" . core_base::getUser('name') ."'";
        $sql .= !empty($params['search']['productId']) ? " AND `productId` = '{$params['search']['productId']}' " : "";
        $sql .= !empty($params['search']['addDateStart']) ? " AND `addDate` >= '{$params['search']['addDateStart']}' " : "";
        $sql .= !empty($params['search']['addDateEnd']) ? " AND `addDate` <= '{$params['search']['addDateEnd']}' " : "";
        return $sql;
    }

    /**
     * 描述 ：执行修改数据的sql
     * 作者 ：Zoro.Zhu
    **/
    public static function updateSql($data = array()){
        $sql = "UPDATE `wish_favorites` 
        SET 
            `data` = '{$data['data']}',
            `addName` = '{$data['addName']}',
            `addDate` = '{$data['addDate']}'
        WHERE
            `productId` = '{$data['productId']}'";
        return L::sql($sql);
    }

    /**
     * 描述 ：执行插入数据的sql
     * 作者 ：Zoro.Zhu
    **/
    public static function insertSql($data = array()){
        $data['addName'] = core_base::getUser('name');
        $data['addDate'] = date('Y-m-d H:i:s');
        $sql = "INSERT INTO `wish_favorites`(
             `productId`, `data`, `addName`, `addDate`
        ) VALUES (
             '{$data['productId']}', '[]', '{$data['addName']}', '{$data['addDate']}'
        ) ON DUPLICATE KEY UPDATE `productId`= VALUES(`productId`)";
        return L::sql($sql);
    }

    /**
     * 描述：根据主键获取数据
     * 作者：Zoro.Zhu
    **/
    public static function getKeyInfo($key){
        $sql = "SELECT
             `productId`, `data`, `addName`, `addDate`
        FROM
            `wish_favorites`
        WHERE 
            `productId` = '{$key}'";
        return L::sql($sql);
    }

}